package com.example.Service;

import com.example.config.AliyunSmsConfig;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class SmsServiceImpl implements SmsService {

    @Resource
    private AliyunSmsConfig aliyunSmsConfig;

    @Override
    public boolean sendVerificationCode(String phone, String code) {
        try {
            SendSmsResponse response = aliyunSmsConfig.sendSms(
                    phone,
                    "阿里云短信测试", // 阿里云短信签名
                    "SMS_154950909", // 阿里云短信模板代码
                    "{\"code\":\"" + code + "\"}" // 模板参数
            );
//            log.info(response.getCode());
            return "OK".equals(response.getCode());
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
